<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .container {
      width: 100vw;
      height: 400px;
      display: flex;
    }
    .item {
      flex: 1;
      margin-right: 15px;
      background-color: pink;
      text-align: center;
      position: relative;
    }
    .item span {
      line-height: 400px;
    }
    .block {
      width: 100px;
      height: 50px;
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      margin: auto;
    }
    .block1 {
      background-color: red;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .block2 {
      width: 200px;
      height: 200px;
      background-color: red;
      position: absolute;
      top: 50%;
      left: 50%;
      margin-left: -100px;
      margin-top: -100px;
    }
    .flex-item {
      display: flex;
      justify-content: center;
      flex-direction: column;
    }
  </style>
  <body>
    <div class="container">
      <div class="item">
        <span>行内元素垂直居中</span>
      </div>
      <div class="item">
        <!-- 方案一 绝对定位结合margin: auto，但是必须知道高宽 兼容性好-->
        <div class="block">绝对定位元素的垂直居中对齐</div>
      </div>
      <div class="item">
        <!-- 方案二 -->
         <div class="block1">绝对定位可结合transform实现居中</div>
      </div>
      <div class="item">
        <!-- 方案三 -->
        <div class="block2">绝对定位元素，可结合top和margin实现，但是必须知道尺寸</div>
      </div>
      <div class="item flex-item">
        <!-- 方案四 flex布局实现垂直居中 -->
         <div class="block3">flex布局实现垂直居中</div>
      </div>
    </div>

  </body>
</html>
